unit Form_Client;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, rtcInfo, rtcConn, rtcTcpCli, ExtCtrls, RzPanel, StdCtrls, RzEdit,
  RzButton, Mask, RzBtnEdt, rtcDataCli, rtcMsgCli;

type
  TFormClient = class(TForm)
    TcpClient_A: TRtcTcpClient;
    RzToolbar1: TRzToolbar;
    RzMemo1: TRzMemo;
    RzToolButton1: TRzToolButton;
    Edit_Serv: TRzButtonEdit;
    Edit_Port: TRzButtonEdit;
    RzToolButton2: TRzToolButton;
    RzToolButton3: TRzToolButton;
    RtcMessageClient1: TRtcMessageClient;
    Btnx_1: TRzToolButton;
    Btnx_2: TRzToolButton;
    procedure RzToolButton1Click(Sender: TObject);
    procedure TcpClient_AConnectFail(Sender: TRtcConnection);
    procedure TcpClient_AConnectError(Sender: TRtcConnection;
      E: Exception);
    procedure RzToolButton2Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure RzToolButton3Click(Sender: TObject);
    procedure Btnx_1Click(Sender: TObject);
    procedure Btnx_2Click(Sender: TObject);
  private
    FClikNumb:Integer;
  public
    procedure AddText(AText:string);
  end;

var
  FormClient: TFormClient;

implementation


{$R *.dfm}

procedure TFormClient.RzToolButton1Click(Sender: TObject);
begin
  TcpClient_A.ServerAddr:=Trim(Edit_Serv.Text);
  TcpClient_A.ServerPort:=Trim(Edit_Port.Text);

  RtcMessageClient1.ServerAddr:=Trim(Edit_Serv.Text);
  RtcMessageClient1.ServerPort:=Trim(Edit_Port.Text);
end;

procedure TFormClient.AddText(AText: string);
begin
  RzMemo1.Lines.Add(AText);
end;

procedure TFormClient.TcpClient_AConnectFail(Sender: TRtcConnection);
begin
  AddText('fail');
end;

procedure TFormClient.TcpClient_AConnectError(Sender: TRtcConnection;
  E: Exception);
begin
  AddText('error');
end;

procedure TFormClient.RzToolButton2Click(Sender: TObject);
begin
  FClikNumb:=0;
end;

procedure TFormClient.FormShow(Sender: TObject);
begin
  FClikNumb:=0;
end;

procedure TFormClient.RzToolButton3Click(Sender: TObject);
var
  StrsA:TStringList;
  I:Integer;
begin
  {StrsA:=TStringList.Create;
  StrsA.LoadFromFile('0001.txt');

  TcpClient_A.Connect();
  TcpClient_A.Write(StrsA.Strings[FClikNumb]);
  Inc(FClikNumb);

  FreeAndNil(StrsA);}

  for I:=0 to 9 do
  begin
    TcpClient_A.Connect();
    TcpClient_A.Write(Format('%D',[I]));
  end;
end;

procedure TFormClient.Btnx_1Click(Sender: TObject);
begin
  TcpClient_A.Connect();
  TcpClient_A.Write('0123456789');
end;

procedure TFormClient.Btnx_2Click(Sender: TObject);
var
  ListA:TStringList;
  TempA:string;
begin

  try
    ListA:=TStringList.Create;
    ListA.LoadFromFile('test.txt');
    TempA:=ListA.Text;

    {if Pos(#$D#$A,TempA)>0 then
    begin
      TempA:=StringReplace(TempA,#$D#$A,'',[rfReplaceAll]);
    end;}
    //TempA:=StringReplace(TempA,#13#10,'',[rfReplaceAll]);

    TcpClient_A.Connect();
    TcpClient_A.Write(TempA);    
  finally
    FreeAndNil(ListA);
  end;
end;

end.
